#include <stdbool.h>
#include <stdint.h>

#include "delay.h"
#include "spi.h"

#define IMU_SCAN_FREQ (500)
#define MPU9250_SPI hspi1
#define MPU9250_CS_GPIO GPIOA
#define MPU9250_CS_PIN GPIO_PIN_4

#define DEVIATION_ACCEL_X (1140)
#define DEVIATION_ACCEL_Y (-1847)
#define DEVIATION_ACCEL_Z (219)
#define DEVIATION_GYRO_X (-59)
#define DEVIATION_GYRO_Y (-7)
#define DEVIATION_GYRO_Z (131)

typedef enum GyroRange_ {
  GYRO_RANGE_250DPS = 0,
  GYRO_RANGE_500DPS,
  GYRO_RANGE_1000DPS,
  GYRO_RANGE_2000DPS,
} GyroRange;

typedef enum AccelRange_ {
  ACCEL_RANGE_2G = 0,
  ACCEL_RANGE_4G,
  ACCEL_RANGE_8G,
  ACCEL_RANGE_16G,
} AccelRange;

typedef enum DLPFBandwidth_ {
  DLPF_BANDWIDTH_184HZ = 0,
  DLPF_BANDWIDTH_92HZ,
  DLPF_BANDWIDTH_41HZ,
  DLPF_BANDWIDTH_20HZ,
  DLPF_BANDWIDTH_10HZ,
  DLPF_BANDWIDTH_5HZ,
} DLPFBandwidth;

typedef enum SampleRateDivider_ {
  LP_ACCEL_ODR_0_24HZ = 0,
  LP_ACCEL_ODR_0_49HZ,
  LP_ACCEL_ODR_0_98HZ,
  LP_ACCEL_ODR_1_95HZ,
  LP_ACCEL_ODR_3_91HZ,
  LP_ACCEL_ODR_7_81HZ,
  LP_ACCEL_ODR_15_63HZ,
  LP_ACCEL_ODR_31_25HZ,
  LP_ACCEL_ODR_62_50HZ,
  LP_ACCEL_ODR_125HZ,
  LP_ACCEL_ODR_250HZ,
  LP_ACCEL_ODR_500HZ,
} SampleRateDivider;

/**
 * @brief 初始化MPU6500
 *
 * @return uint8_t
 */
uint8_t MPU6500_Init(void);

/**
 * @brief 获取IMU数据
 *
 * @param AccData 加速度数据地址
 * @param GyroData 陀螺仪数据地址
 */
void MPU6500_GetData(int16_t* AccData, int16_t* GyroData);
